<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('阀门采集数据')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
    <div class="ui-layout-west">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa icon-grid"></i> 住户资料
                </div>
                <div class="box-tools pull-right">
                    <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i class="fa fa-refresh"></i></button>
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="container-div">
            <div class="row">
                <div class="col-sm-12 search-collapse">
                    <form id="formId">
                        <input type="hidden" id="locationId" name="locationId">
                        <div class="select-list">
                            <ul>
                                <li>
                                    <label>地址：</label>
                                    <input type="text" id="locationName" name="locationName" >
                                </li>
                                <li>
                                    <label>阀门ID：</label>
                                    <input type="text" name="valveId" id="valveId" th:value="${valveId}"/>
                                </li>
                                <li class="select-time">
                                    <label>采集时间： </label>
                                    <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]" th:value="${beginTime}"/>
                                    <span>-</span>
                                    <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]" th:value="${endTime}"/>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="getValve()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>
                <div class="col-sm-12 select-table table-striped">
                    <div class="col-sm-12" id="valve" style="height:400px;border:1px solid lightgrey;background:#e5e3dc;">
                    </div>
                </div>
            </div>
        </div>
    </div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: echarts-js" />
<th:block th:include="include :: layout-latest-js" />
<th:block th:include="include :: ztree-js" />
<script th:inline="javascript">
    var prefix = ctx + "report/valve";

    $(function() {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({ initClosed: panehHidden, west__size: 185 });
        getValve();
        queryLocationTree();
    });

    function queryLocationTree()
    {
        var url = ctx + "base/location/treeData";
        var options = {
            url: url,
            expandLevel: 2,
            onClick : zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            $("#locationId").val(treeNode.id);
            queryValve(treeNode.id);
        }
    }

    $('#btnExpand').click(function() {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    $('#btnCollapse').click(function() {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    $('#btnRefresh').click(function() {
        queryLocationTree();
    });

    /**
     * 根据地址查询阀门
     */
    function queryValve(locationId){
        $.ajax({
            url: ctx + "base/valve/info/selectValveByLocation/"+locationId,
            cache: false,
            contentType: false,
            processData: false,
            type: 'POST',
            success: function (result) {
                $("#valveId").val(result);
                getValve();
            }
        });
    }

    function getValve(){
        var lineChart = echarts.init(document.getElementById('valve'));
        var names=[];
        var indoors=[];
        var apertures=[];
        var temps=[];
        lineChart.showLoading();//加载动画

        $.ajax({
            url: prefix + '/valveSummary',
            async: true,
            type: "POST",
            dataType: "json",
            data: $("#formId").serializeArray(),
            success: function (json) {
                for (var i = 0; i < json.data.length; i++) {
                    names.push(json.data[i].createTime);
                    indoors.push(json.data[i].indoor);
                    temps.push(json.data[i].temp);
                    apertures.push(json.data[i].aperture);

                }
                lineChart.hideLoading();//隐藏加载动画
                lineChart.setOption({
                    title: {
                        text: '室内温度/设置温度/阀门开度曲线图'
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    legend: {
                        data: ['室内温度', '设置温度' , '阀门开度']
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: names
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [{
                        name: '室内温度',
                        data: indoors,
                        type: 'line',
                        smooth: true
                    },{
                        name: '设置温度',
                        data: temps,
                        type: 'line',
                        smooth: true
                    },{
                        name: '阀门开度',
                        data: apertures,
                        type: 'line',
                        smooth: true
                    }
                    ]
                });
            }
        });
    }
</script>
</body>